layer.config({
    extend: 'extend/layer.ext.js'
});

$("#detail").hide();
$("#mine").hide();
var ws;
var errorclose = false;
var mode = 0;
var viewop = false;
window.onload = function () {
    $.get("/sRaw/detail.html", function (data) {
        $('.toend').append(data);
    });
    Refresh();
    $('[data-toggle="popover"]').popover();

    $("#connecting").modal({
        backdrop: 'static'
    });

    setTimeout(function () {
        $("#connectingtext").css('background-color', '#7C49FF');
        $("#connectingtext").text('正在连接服务器...');
        setTimeout(function () {
            $.get("/Interesting/Connectx", function (data) {
                if (data != "Success") {
                    errorclose = true;
                    $("#connectingtext").text('连接失败！' + data);
                    return;
                }

            });
            ws = new WebSocket('ws://' + window.location.hostname + ':' + window.location.port + '/Interesting/Connectx');
            ws.onopen = function () {
                $("#connectingtext").text('已响应，正在交换数据...');
                if (ws.readyState == WebSocket.OPEN) {
                    ws.send('test');
                }
                else {
                    errorclose = true;
                    $("#connectingtext").text('连接失败！服务器连接断开！刷新页面尝试重新连接。');
                }
            }
            ws.onmessage = function (evt) {
                console.log(evt);
                if (evt.data == "anotherlogin") {
                    $("#discontext").text("您的账号在另一个设备登录，您已被迫下线！");
                    return;
                }
                if (mode == -1)
                    return;
                var s = evt.data;
                s = JSON.parse(evt.data);
                if (mode == 0) {
                    if (s.state != "Error") {
                        if (s.state == "alreadyonline")
                            alert("当前账号正在游戏中，对方已经被迫下线！");
                        $("#connectingtext").text('数据交换成功！正在登录服务器...');
                        mode = -1;
                        setTimeout(function () {
                            $('#onlinecount').text('在线人数：' + s.onlines);
                            $("#connectingtext").text('服务器已连接。');
                            $("#connectingtext").css('background-color', '#1B8C18');
                            setTimeout(function () {
                                $("#connecting").modal('hide');
                            }, 1);
                        }, 1);
                    } else {
                        errorclose = true;
                        $("#connectingtext").text('连接失败！服务器连接断开！刷新页面尝试重新连接。');
                        ws.close();
                        return;
                    }
                }
            }
            ws.onerror = function (evt) {
                errorclose = true;
                $("#connectingtext").text('服务器连接失败！刷新页面尝试重新连接。');
            }
            ws.onclose = function (evt) {
                console.log(evt);
                if (!errorclose) {
                    $("#disconnected").modal({
                        backdrop: 'static'
                    });
                }
            }

        }, 1);
    }, 1);



}

$('#connecting').on('hidden.bs.modal', function (e) {

    //$("#notice").modal('show');

});

$('#shownotice').click(function () {

    $("#notice").modal('show');


});

function Refresh() {


}

$(document).on('click', '.skillview', function () {
    var itemid = $(this).attr('itemid');
    if (itemid == -1)
        return;
    var post = {};

    post["hash"] = itemid;
    $.post('/Interesting/SSK', post, function (data) {
        if (data == "Error") {
            $("#discontext").text("请求数据失败！请刷新重试！");
            ws.close();
            $("#disconnected").modal({
                backdrop: 'static'
            });
            return;
        } else {
            var ATK = 0;
            var Class = "";
            var Cost = 0;
            var DOWN = 0;
            var Level = 0;
            var MaxLevel = 0;
            var Name = "";
            var Note = "";
            var NowEXP = 0;
            var Paid = 0;
            var Properties = "";
            var SType = "";
            var Type = "";
            var UP = 0;
            var UpEXP = 0;
            var canLevelup;
            var canPaid;
            var iClass = "";
            ATK = data.ATK;
            Class = data.Class;
            Cost = data.Cost;
            DOWN = data.DOWN;
            Level = data.Level;
            MaxLevel = data.MaxLevel;
            Name = data.Name;
            Note = data.Note;
            NowEXP = data.NowEXP;
            Paid = data.Paid;
            Properties = data.Properties;
            SType = data.SType;
            Type = data.Type;
            UP = data.UP;
            UpEXP = data.UpEXP;
            canLevelup = data.canLevelup;
            canPaid = data.canPaid;
            iClass = data.iClass;

            var snote = {};
            var as = '<span class="label label-primary">名称：</span><span class="label detailname" style="margin-left:5px;">未知</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">品质：</span><span class="label detailstype" style="margin-left:5px;">无</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">伤害：</span><span class="label label-success detailttype" style="margin-left:5px;">未知</span><br/>' +
                '<div style="margin-top:10px"></div>';
            if (Note.length != 0) {
                snote = Note.split('\r\n');
                for (var i = 0; i < snote.length; i++) {
                    as += '<span class="label detailnote' + i + '" style="background-color:#39C1C0;">无</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }

            }

            as += '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                    '<div style="margin-top:10px"></div>' +
                    '<span class="label label-primary">COST：</span><span class="label label-danger detailcost" style="margin-left:5px;">' + Cost + '</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                    '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">等级：</span><span class="label label-info detaillevel" style="margin-left:5px;">' + Level + '</span><br/>' +
                 '<div style="margin-top:10px"></div>';
            if (canLevelup) {
                as += '<span class="label label-primary">经验值：</span><span class="label label-info detailexp" style="margin-left:5px;">' + NowEXP + '/' + (UpEXP - NowEXP) + '</span><br/>' +
                 '<div style="margin-top:10px"></div>';
            }


            if (!canLevelup || !canPaid) {
                as += '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                    '<div style="margin-top:10px"></div>'

                if (!canLevelup) {
                    as += '<span class="label label-danger" style="margin-right:5px;">无法升级</span>';

                }

                if (!canPaid) {
                    as += '<span class="label label-danger" style="margin-right:5px;">不可出售</span>';

                }

            }

            var p2 = pinyin.getFullChars(SType).toLowerCase();
            var pcolor = color[p2];
            $('.detailbody').empty();
            $('.detailbody').append(as);
            $('.detailtitle').text(Name);
            $('.detailstype').text(SType);
            $('.detailtitle').css('background-color', pcolor);
            $('.detailstype').css('background-color', pcolor);
            $('.detailname').text(Name);
            $('.detailname').css('background-color', pcolor);
            $('.detailttype').text(Type);
            if (snote.length != 0) {
                for (var i = 0; i < snote.length; i++) {
                    $('.detailnote' + i).text(snote[i]);
                }

            }
            $('.detail').modal('show');
        }



    }, 'json');


});

$(document).on("click", ".itemview", function () {
    var itemid = $(this).attr('itemid');
    if (itemid == -1)
        return;
    var post = {};

    post["hash"] = itemid;
    $.post("/Interesting/SS", post, function (data) {
        if (data == "Error") {
            $("#discontext").text("请求数据失败！请刷新重试！");
            ws.close();
            $("#disconnected").modal({
                backdrop: 'static'
            });
            return;
        } else {
            var HP = 0;
            var FireArmor = 0;
            var IceArmor = 0;
            var NaturalArmor = 0;
            var WaterArmor = 0;
            var LightArmor = 0;
            var DarkArmor = 0;
            var SpaceArmor = 0;
            var FireUP = 0;
            var IceUP = 0;
            var NaturalUP = 0;
            var WaterUP = 0;
            var LightUP = 0;
            var DarkUP = 0;
            var SpaceUP = 0;
            var Level = 0;
            var Description = "";
            var Name = "";
            var Equips = "";
            var Class = "";
            var SType = "";
            var Note = "";
            var canDestroy;
            var canSell;
            var SellCost = 0;
            var Type = "";
            HP = data.HP;
            FireArmor = data.FireArmor;
            IceArmor = data.IceArmor;
            NaturalArmor = data.NaturalArmor;
            WaterArmor = data.WaterArmor;
            LightArmor = data.LightArmor;
            DarkArmor = data.DarkArmor;
            SpaceArmor = data.SpaceArmor;
            FireUP = data.FireUP;
            IceUP = data.IceUP;
            NaturalUP = data.NaturalUP;
            WaterUP = data.WaterUP;
            LightUP = data.LightUP;
            DarkUP = data.DarkUP;
            SpaceUP = data.SpaceUP;
            Level = data.Level;
            Description = data.Description;
            Name = data.Name;
            Equips = data.Equips;
            Class = data.Class;
            SType = data.SType;
            Note = data.Note;
            canDestroy = data.canDestroy;
            canSell = data.canSell;
            SellCost = data.SellCost;
            Type = data.Type;
            var snote = {};
            var sdes = {};
            var as = '<span class="label label-primary">名称：</span><span class="label detailname" style="margin-left:5px;">未知</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">品质：</span><span class="label detailstype" style="margin-left:5px;">无</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">类型：</span><span class="label label-success detailttype" style="margin-left:5px;">未知</span><br/>' +
                '<div style="margin-top:10px"></div>';
            if (Note.length != 0) {
                snote = Note.split('\r\n');
                for (var i = 0; i < snote.length; i++) {
                    as += '<span class="label detailnote' + i + '" style="background-color:#39C1C0;">无</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }

            }
            if (Description.length != 0) {
                sdes = Description.split('\r\n');
                for (var i = 0; i < sdes.length; i++) {
                    as += '<span class="label label-warning detaildescription' + i + '">无</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }

            }
            if (HP != 0 || FireArmor != 0 || IceArmor != 0 || NaturalArmor != 0 || WaterArmor != 0 || LightArmor != 0 || DarkArmor != 0 || SpaceArmor != 0) {
                as += '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                    '<div style="margin-top:10px"></div>';
                if (HP != 0) {
                    as += '<span class="label label-info">生命值：</span><span class="label label-success detailhp" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (FireArmor != 0) {
                    as += '<span class="label label-info">火焰抗性：</span><span class="label label-success detailfirearmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (IceArmor != 0) {
                    as += '<span class="label label-info">冰霜抗性：</span><span class="label label-success detailicearmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (NaturalArmor != 0) {
                    as += '<span class="label label-info">自然抗性：</span><span class="label label-success detailnaturalarmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (WaterArmor != 0) {
                    as += '<span class="label label-info">风水抗性：</span><span class="label label-success detailwaterarmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (LightArmor != 0) {
                    as += '<span class="label label-info">光明抗性：</span><span class="label label-success detaillightarmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (DarkArmor != 0) {
                    as += '<span class="label label-info">暗影抗性：</span><span class="label label-success detaildarkarmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (SpaceArmor != 0) {
                    as += '<span class="label label-info">时空抗性：</span><span class="label label-success detailspacearmor" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
            }
            if (FireUP != 0 || IceUP != 0 || NaturalUP != 0 || WaterUP != 0 || LightUP != 0 || DarkUP != 0 || SpaceUP != 0) {
                as += '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                    '<div style="margin-top:10px"></div>';
                if (FireUP != 0) {
                    as += '<span class="label label-info">火焰增长：</span><span class="label label-success detailfireup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (IceUP != 0) {
                    as += '<span class="label label-info">冰霜增长：</span><span class="label label-success detailiceup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (NaturalUP != 0) {
                    as += '<span class="label label-info">自然增长：</span><span class="label label-success detailnaturalup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (WaterUP != 0) {
                    as += '<span class="label label-info">风水增长：</span><span class="label label-success detailwaterup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (LightUP != 0) {
                    as += '<span class="label label-info">光明增长：</span><span class="label label-success detaillightup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (DarkUP != 0) {
                    as += '<span class="label label-info">暗影增长：</span><span class="label label-success detaildarkup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
                if (SpaceUP != 0) {
                    as += '<span class="label label-info">时空增长：</span><span class="label label-success detailspaceup" style="margin-left:5px;">0</span><br/>' +
                        '<div style="margin-top:10px"></div>';
                }
            }
            if (!canDestroy || !canSell) {
                as += '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                    '<div style="margin-top:10px"></div>'

                if (!canDestroy) {
                    as += '<span class="label label-danger" style="margin-right:5px;">不可销毁</span>';

                }

                if (!canSell) {
                    as += '<span class="label label-danger" style="margin-right:5px;">不可出售</span>';

                }

            }
            as += '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label detailsell" style="background-color:#2537AB">出售价格：0 金币</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label detailclass" style="background-color:#026716">职业限制：未知</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label detaillevel" style="background-color:#37AB8F">评分：0</span>';

            $('.detailbody').empty();
            $('.detailbody').append(as);
            $('.detailtitle').text(Name);
            $('.detailstype').text(SType);
            $('.detailttype').text(Type);
            var p2 = pinyin.getFullChars(SType).toLowerCase();
            var pcolor = color[p2];
            $('.detailtitle').css('background-color', pcolor);
            $('.detailstype').css('background-color', pcolor);
            $('.detailname').text(Name);
            $('.detailname').css('background-color', pcolor);
            $('.detaillevel').text('评分：' + Level);
            $('.detailsell').text('出售价格：' + SellCost + ' 金币');
            $('.detailclass').text('职业限制：' + Class);
            if (snote.length != 0) {
                for (var i = 0; i < snote.length; i++) {
                    $('.detailnote' + i).text(snote[i]);
                }

            }
            if (sdes.length != 0) {
                for (var i = 0; i < sdes.length; i++) {
                    $('.detaildescription' + i).text(sdes[i]);
                }

            }
            $('.detailhp').text(HP);
            $('.detailfirearmor').text(FireArmor);
            $('.detailicearmor').text(IceArmor);
            $('.detailnaturalarmor').text(NaturalArmor);
            $('.detailwaterarmor').text(WaterArmor);
            $('.detaillightarmor').text(LightArmor);
            $('.detaildarkarmor').text(DarkArmor);
            $('.detailspacearmor').text(SpaceArmor);

            $('.detailfireup').text(FireUP);
            $('.detailiceup').text(IceUP);
            $('.detailnaturalup').text(NaturalUP);
            $('.detailwaterup').text(WaterUP);
            $('.detaillightup').text(LightUP);
            $('.detaildarkup').text(DarkUP);
            $('.detailspaceup').text(SpaceUP);

            $('.detail').modal('show');
        }
    }, "json");

});

$(document).on('click', '.viewopen', function () {

    $.post("/Interesting/C", function (data) {
        if (data == "Error") {
            $("#discontext").text("请求数据失败！请刷新重试！");
            ws.close();
            $("#disconnected").modal({
                backdrop: 'static'
            });
            return;

        } else {
            if (viewop) {
                viewop = false;
                $('.viewopen').text('查看所有启用技能');
            }
            else {
                viewop = true;
                $('.viewopen').text('查看全部技能');               
            }
            
            $('.viewsopen').empty();
            var iputong = 0;
            var ixiyou = 0;
            var ishishi = 0;
            var ichuanshuo = 0;
            var ibanshen = 0;
            var izhenshen = 0;
            var ibuxiu = 0;
            var wuli = "label-warning";
            var mofa = "label-info";
            var hunhe = "label-danger";
            var fuzhu = "label-success";
            var s = "";
            $.each(data.Skills, function (key, value) {
                if (viewop) {
                    if (!value.Show)
                        return true;
                }
                var p = pinyin.getFullChars(value.SType).toLowerCase();
                var t = pinyin.getFullChars(value.Type).toLowerCase();
                var ts = "";
                eval('ts = ' + t);
                var pcolor = color[p];
                var q = "禁用";
                if (!value.Show)
                    q = "启用";
                s += '<span class="label" style="background-color:' + pcolor + '">' + value.SType + '</span><span class="label ' + ts + '" style="margin-left:5px;">' + value.Type + '</span><span class="label skillview" style="margin-left:5px;background-color:' + pcolor + '" itemid="' + value.Hash + '">' + value.Name + '</span>';
                if (viewop) {

                    s += '<br/>';
                } else {

                    s += '<a href="javascript:;" class="label label-primary skillenable" style="margin-top:3px;float:right" itemid="' + value.Hash + '">' + q + '</a><br/>';
                }
                s += '<div style="margin-top:10px"></div>';
                eval('i' + p + '++;');

            });

            $('.viewsopen').append(s);

            $('.sputong').text(iputong + '普通');
            $('.sxiyou').text(ixiyou + '稀有');
            $('.sshishi').text(ishishi + '史诗');
            $('.schuanshuo').text(ichuanshuo + '传说');
            $('.sbanshen').text(ibanshen + '半神');
            $('.szhenshen').text(izhenshen + '真神');
            $('.sbuxiu').text(ibuxiu + '不朽');
        }
    }, 'json');


});

$('#showself').click(function () {
    $.post("/Interesting/C", function (data) {
        if (data == "Error") {
            $("#discontext").text("请求数据失败！请刷新重试！");
            ws.close();
            $("#disconnected").modal({
                backdrop: 'static'
            });
            return;

        } else {
            $('#showself').prop('disabled', true);
            setTimeout(function () {
                $('#showself').prop('disabled', false);
            }, 5000);
            $("#mine").hide();
            var HP = 1000;
            var FireArmor = 0;
            var IceArmor = 0;
            var NaturalArmor = 0;
            var WaterArmor = 0;
            var LightArmor = 0;
            var DarkArmor = 0;
            var SpaceArmor = 0;
            var FireUP = 0;
            var IceUP = 0;
            var NaturalUP = 0;
            var WaterUP = 0;
            var LightUP = 0;
            var DarkUP = 0;
            var SpaceUP = 0;
            var Level = 0;
            var i = 0;
            var Levelb = 0;
            var Percent = data.EXP / (data.EXP + data.NextEXP);
            var Percent0 = Percent.toFixed(0);
            Percent = Percent.toFixed(2);
            $('#minetitle').text('个人面板');
            $('#minecontext').empty();
            var s = '<span class="label label-primary">职业：</span><span class="label label-success" style="margin-left:5px" id="myclass">' + data.Class + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">等级：</span><span class="label label-success" style="margin-left:5px" id="mylevel">' + data.Level + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">活力剩余：</span><span class="label label-warning" style="margin-left:5px" id="myactive">' + data.ActivePoint + '点伤害</span><span class="label label-success nowdamage" style="margin-left:5px">100%伤害</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-primary">经验值：</span><span class="label label-info" style="margin-left:5px" id="myexp">' + data.EXP + '/' + (data.EXP + data.NextEXP) + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<div class="progress">' +
                '<div class="progress-bar progress-bar-info progress-bar-striped active expprogress" role="progressbar" style="min-width: 2em;width: ' + Percent + '%">' +
                '<span class="exptext">' + Percent0 + '%</span>' +
                '</div>' +
                '</div>' +
                '<div style="margin-top:10px"></div>' +
                '<button class="btn btn-success viewstatus" style="width:100%">查看状态/BUFF</button>' +
                '<div style="margin-top:10px"></div>' +
                '<div class="statuses"></div>' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">生命值：</span><span class="label label-info myhp" style="margin-left:5px">' + HP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">火焰抗性：</span><span class="label label-warning myfirear" style="margin-left:5px">' + FireArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">冰霜抗性：</span><span class="label label-warning myicear" style="margin-left:5px">' + IceArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">自然抗性：</span><span class="label label-warning mynaturalar" style="margin-left:5px">' + NaturalArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">风水抗性：</span><span class="label label-warning mywaterar" style="margin-left:5px">' + WaterArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">光明抗性：</span><span class="label label-warning mylightar" style="margin-left:5px">' + LightArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">暗影抗性：</span><span class="label label-warning mydarkar" style="margin-left:5px">' + DarkArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-danger">时空抗性：</span><span class="label label-warning myspacear" style="margin-left:5px">' + SpaceArmor + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">火焰增长：</span><span class="label label-info myfireup" style="margin-left:5px">' + FireUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">冰霜增长：</span><span class="label label-info myiceup" style="margin-left:5px">' + IceUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">自然增长：</span><span class="label label-info mynaturalup" style="margin-left:5px">' + NaturalUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">风水增长：</span><span class="label label-info mywaterup" style="margin-left:5px">' + WaterUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">光明增长：</span><span class="label label-info mylightup" style="margin-left:5px">' + LightUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">暗影增长：</span><span class="label label-info mydarkup" style="margin-left:5px">' + DarkUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">时空增长：</span><span class="label label-info myspaceup" style="margin-left:5px">' + SpaceUP + '</span><br />' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">头部：</span><span class="label toubu itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _toubu" style="margin-left:5px;background-color:#333">无等级</span><span class="label __toubu" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="toubu">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">胸甲：</span><span class="label xiongjia itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _xiongjia" style="margin-left:5px;background-color:#333">无等级</span><span class="label __xiongjia" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="xiongjia">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">鞋子：</span><span class="label xiezi itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _xiezi" style="margin-left:5px;background-color:#333">无等级</span><span class="label __xiezi" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="xiezi">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">护手：</span><span class="label hushou itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _hushou" style="margin-left:5px;background-color:#333">无等级</span><span class="label __hushou" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="hushou">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">肩膀：</span><span class="label jianbang itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _jianbang" style="margin-left:5px;background-color:#333">无等级</span><span class="label __jianbang" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="jianbang">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">腿部：</span><span class="label tuibu itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _tuibu" style="margin-left:5px;background-color:#333">无等级</span><span class="label __tuibu" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="tuibu">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">腰带：</span><span class="label yaodai itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _yaodai" style="margin-left:5px;background-color:#333">无等级</span><span class="label __yaodai" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="yaodai">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">披风：</span><span class="label pifeng itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _pifeng" style="margin-left:5px;background-color:#333">无等级</span><span class="label __pifeng" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="pifeng">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">项链：</span><span class="label xianglian itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _xianglian" style="margin-left:5px;background-color:#333">无等级</span><span class="label __xianglian" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="xianglian">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">戒指1：</span><span class="label jiezhi1 itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _jiezhi1" style="margin-left:5px;background-color:#333">无等级</span><span class="label __jiezhi1" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="jiezhi1">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">戒指2：</span><span class="label jiezhi2 itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _jiezhi2" style="margin-left:5px;background-color:#333">无等级</span><span class="label __jiezhi2" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="jiezhi2">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">饰品1：</span><span class="label shipin1 itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _shipin1" style="margin-left:5px;background-color:#333">无等级</span><span class="label __shipin1" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="shipin1">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">饰品2：</span><span class="label shipin2 itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _shipin2" style="margin-left:5px;background-color:#333">无等级</span><span class="label __shipin2" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="shipin2">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">衬衣：</span><span class="label chenyi itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _chenyi" style="margin-left:5px;background-color:#333">无等级</span><span class="label __chenyi" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="chenyi">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label" style="background-color:#8839B3">战袍：</span><span class="label zhanpao itemview" style="margin-left:5px;background-color:#337ab7" itemid="-1">未装备</span><span class="label _zhanpao" style="margin-left:5px;background-color:#333">无等级</span><span class="label __zhanpao" style="margin-left:5px;background-color:#333">评分：0</span><a href="javascript:void(0)" class="label label-danger drop" style="margin-top:2px;float:right" drop="zhanpao">卸下</a><br />' +
                '<div style="margin-top:10px"></div>' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label levelb" style="background-color:#37AB8F">平均评分：0</span>';


            $('#minecontext').append(s);
            $('.statuses').hide();
            var a = [];
            $.each(data.Player, function (key, val) { a[a.length] = key; });
            a.sort();
            $.each(a, function (k, v) {
                var key = v;
                var value = data.Player[v];
                if (value == null || value == "null")
                    return true;
                var post = {};
                post["hash"] = value;
                $.post("/Interesting/SS", post, function (data) {
                    if (data == "Error") {
                        $("#discontext").text("请求数据失败！请刷新重试！");
                        ws.close();
                        $("#disconnected").modal({
                            backdrop: 'static'
                        });
                        return;
                    } else {
                        i++;
                        HP += data.HP;
                        FireArmor += data.FireArmor;
                        IceArmor += data.IceArmor;
                        NaturalArmor += data.NaturalArmor;
                        WaterArmor += data.WaterArmor;
                        LightArmor += data.LightArmor;
                        DarkArmor += data.DarkArmor;
                        SpaceArmor += data.SpaceArmor;
                        FireUP += data.FireUP;
                        IceUP += data.IceUP;
                        NaturalUP += data.NaturalUP;
                        WaterUP += data.WaterUP;
                        LightUP += data.LightUP;
                        DarkUP += data.DarkUP;
                        SpaceUP += data.SpaceUP;
                        Level += data.Level;
                        $('.myhp').text(HP);
                        $('.myfirear').text(FireArmor);
                        $('.myicear').text(IceArmor);
                        $('.mynaturalar').text(NaturalArmor);
                        $('.mywaterar').text(WaterArmor);
                        $('.mylightar').text(LightArmor);
                        $('.mydarkar').text(DarkArmor);
                        $('.myspacear').text(SpaceArmor);
                        $('.myfireup').text(FireUP);
                        $('.myiceup').text(IceUP);
                        $('.mynaturalup').text(NaturalUP);
                        $('.mywaterup').text(WaterUP);
                        $('.mylightup').text(LightUP);
                        $('.mydarkup').text(DarkUP);
                        $('.myspaceup').text(SpaceUP);
                        var p1 = pinyin.getFullChars(data.Equips).toLowerCase();
                        var p2 = pinyin.getFullChars(data.SType).toLowerCase();
                        var pcolor = color[p2];
                        console.log('key:' + key + ',equips:' + data.Equips + ',pinyin:' + p1 + ",value:" + value + ",name:" + data.Name);
                        $('.' + p1).text(data.Name);
                        $('.' + p1).attr('itemid', value);
                        $('.' + p1).css('background-color', pcolor);
                        $('._' + p1).text(data.SType);
                        $('._' + p1).css('background-color', pcolor);
                        $('.__' + p1).text('评分：' + data.Level);
                        $('.__' + p1).css('background-color', '#37AB8F');
                        Levelb = Level / i;
                        Levelb = Levelb.toFixed(0);
                        $('.levelb').text('平均评分：' + Levelb);
                    }

                }, "json");
            });

            if (data.ActivePoint == 0) {
                $('.nowdamage').removeClass('label-success');
                $('.nowdamage').addClass('label-danger');
                $('.nowdamage').text('25%伤害');
            }

            $.each(data.Buff, function (k, v) {
                var st = '';
                if (v.Round == -1) {
                    st += '<span class="label label-success" style="margin-left:5px">剩余：N/A</span>';
                } else {
                    st += '<span class="label label-success" style="margin-left:5px">剩余：' + v.Round + '回合</span>';
                }
                var sss = '<span class="label label-primary">' + k + '：</span>' + st + '<br/>' +
                          '<div style="margin-top:10px"></div>' +
                          '<span class="label label-default">' + v.Description + '</span><br/>' +
                          '<div style="margin-top:10px"></div>';
                $('.statuses').append(sss);

            });
            $("#mine").show();
            $("html,body").animate({ scrollTop: $("#mine").offset().top }, 1000);
        }

    }, "json");


});


$('#showskill').click(function () {
    $.post("/Interesting/C", function (data) {
        if (data == "Error") {
            $("#discontext").text("请求数据失败！请刷新重试！");
            ws.close();
            $("#disconnected").modal({
                backdrop: 'static'
            });
            return;

        } else {

            $('#showskill').prop('disabled', true);
            setTimeout(function () {
                $('#showskill').prop('disabled', false);
            }, 5000);

            $("#mine").hide();
            $("#minetitle").text("我的技能");
            $("#minecontext").empty();
            var c = getJsonLength(data.Skills);
            var s = '<span class="label label-primary">当前拥有：</span><span class="label label-danger" style="margin-left:5px;">' + c + ' 个技能</span>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label sputong" style="background-color:' + putong + '">0普通</span>' +
                '<span class="label sxiyou" style="margin-left:5px;background-color:' + xiyou + '">0稀有</span>' +
                '<span class="label sshishi" style="margin-left:5px;background-color:' + shishi + '">0史诗</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label schuanshuo" style="background-color:' + chuanshuo + '">0传说</span>' +
                '<span class="label sbanshen" style="margin-left:5px;background-color:' + banshen + '">0半神</span>' +
                '<span class="label szhenshen" style="margin-left:5px;background-color:' + zhenshen + '">0真神</span>' +
                '<span class="label sbuxiu" style="margin-left:5px;background-color:' + buxiu + '">0不朽</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label label-success">被禁用的技能不会在战斗中被抽到</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<button class="btn btn-primary viewopen" style="width:100%">查看所有启用技能</button>' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>' +
                '<div class="viewsopen">';
            var iputong = 0;
            var ixiyou = 0;
            var ishishi = 0;
            var ichuanshuo = 0;
            var ibanshen = 0;
            var izhenshen = 0;
            var ibuxiu = 0;
            var wuli = "label-warning";
            var mofa = "label-info";
            var hunhe = "label-danger";
            var fuzhu = "label-success";
            $.each(data.Skills, function (key, value) {
                var p = pinyin.getFullChars(value.SType).toLowerCase();
                var t = pinyin.getFullChars(value.Type).toLowerCase();
                var ts = "";
                eval('ts = ' + t);
                var pcolor = color[p];
                var q = "禁用";
                if (!value.Show)
                    q = "启用";
                s += '<span class="label" style="background-color:' + pcolor + '">' + value.SType + '</span><span class="label ' + ts + '" style="margin-left:5px;">' + value.Type + '</span><span class="label skillview" style="margin-left:5px;background-color:' + pcolor + '" itemid="' + value.Hash + '">' + value.Name + '</span><a href="javascript:;" class="label label-primary skillenable" style="margin-top:3px;float:right" itemid="' + value.Hash + '">' + q + '</a><br/>' +
                    '<div style="margin-top:10px"></div>';
                eval('i' + p + '++;');

            });

            s += '</div>';
            $('#minecontext').append(s);

            $('.sputong').text(iputong + '普通');
            $('.sxiyou').text(ixiyou + '稀有');
            $('.sshishi').text(ishishi + '史诗');
            $('.schuanshuo').text(ichuanshuo + '传说');
            $('.sbanshen').text(ibanshen + '半神');
            $('.szhenshen').text(izhenshen + '真神');
            $('.sbuxiu').text(ibuxiu + '不朽');


            $("#mine").show();
            $("html,body").animate({ scrollTop: $("#mine").offset().top }, 1000);
        }
    }, "json");
});

$('#showbackpack').click(function () {
    $.post("/Interesting/C", function (data) {
        if (data == "Error") {
            $("#discontext").text("请求数据失败！请刷新重试！");
            ws.close();
            $("#disconnected").modal({
                backdrop: 'static'
            });
            return;

        } else {
            $('#showbackpack').prop('disabled', true);
            setTimeout(function () {
                $('#showbackpack').prop('disabled', false);
            }, 5000);

            $("#mine").hide();
            $("#minetitle").text("我的背包");
            $("#minecontext").empty();
            if (getJsonLength(data.Items) == 0) {
                alert('背包里空空如也！');
                return;
            }
            var c = getJsonLength(data.Items);
            var s = '<span class="label label-primary">当前拥有：</span><span class="label label-danger" style="margin-left:5px;">' + c + ' 种物品</span>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label iputong" style="background-color:' + putong + '">0普通</span>' +
                '<span class="label ixiyou" style="margin-left:5px;background-color:' + xiyou + '">0稀有</span>' +
                '<span class="label ishishi" style="margin-left:5px;background-color:' + shishi + '">0史诗</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<span class="label ichuanshuo" style="background-color:' + chuanshuo + '">0传说</span>' +
                '<span class="label ibanshen" style="margin-left:5px;background-color:' + banshen + '">0半神</span>' +
                '<span class="label izhenshen" style="margin-left:5px;background-color:' + zhenshen + '">0真神</span>' +
                '<span class="label ibuxiu" style="margin-left:5px;background-color:' + buxiu + '">0不朽</span><br/>' +
                '<div style="margin-top:10px"></div>' +
                '<DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px"></DIV>' +
                '<div style="margin-top:10px"></div>';
            var iputong = 0;
            var ixiyou = 0;
            var ishishi = 0;
            var ichuanshuo = 0;
            var ibanshen = 0;
            var izhenshen = 0;
            var ibuxiu = 0;

            $.each(data.Items, function (key, value) {
                var p = pinyin.getFullChars(value.SType).toLowerCase();
                var pcolor = color[p];
                s += '<span class="label" style="background-color:' + pcolor + '">' + value.SType + '</span><span class="label itemview" style="margin-left:5px;background-color:' + pcolor + '" itemid="' + value.Hash + '">' + value.Name + '</span><span class="label" style="margin-left:5px;background-color:#8839B3">' + value.Count + '件</span><a href="javascript:;" class="label label-danger itemdestroy" style="margin-top:3px;float:right" hash="' + value.Hash + '">销毁</a><a href="javascript:;" class="label label-warning itemuse" style="margin-right:5px;margin-top:3px;float:right" hash="' + value.Hash + '">装备/使用</a><br/>' +
                    '<div style="margin-top:10px"></div>';
                eval('i' + p + '++;');

            });

            $('#minecontext').append(s);

            $('.iputong').text(iputong + '普通');
            $('.ixiyou').text(ixiyou + '稀有');
            $('.ishishi').text(ishishi + '史诗');
            $('.ichuanshuo').text(ichuanshuo + '传说');
            $('.ibanshen').text(ibanshen + '半神');
            $('.izhenshen').text(izhenshen + '真神');
            $('.ibuxiu').text(ibuxiu + '不朽');


            $("#mine").show();
            $("html,body").animate({ scrollTop: $("#mine").offset().top }, 1000);
        }
    }, "json");


});


$(document).on("click", ".drop", function () {
    var drop = $(this).attr('drop');
    var itemhash = $('.' + drop).attr('itemid');
    if (itemhash == -1) {
        alert("你不能这么做！");
        return;
    }
    var post = {};
    post["pos"] = drop;
    $.post("/Interesting/D", post, function (data) {
        if (data == "Error") {
            alert("卸下装备失败！");
            return;
        } else {
            $('#showself').click();
            alert("卸下装备成功！已放回背包！");
        }

    });

});

$(document).on("click", ".itemdestroy", function () {
    var hash = $(this).attr('hash');
    var result = prompt("请输入要销毁的数量，大于持有数量或输入-1销毁全部。");
    if (!/^(\+|-)?(\d+)(\.\d*)?$/g.test(result)) {
        alert('请输入整数！');
    } else {
        var post = {};
        post["hash"] = hash;
        post["c"] = result;
        $.post('/Interesting/Des', post, function (data) {
            if (data == "Error") {
                alert('操作失败！');
            } else if (data == "Cant") {
                alert('你不能这么做！');
            }
            else {
                $('#showbackpack').click();
                alert('操作成功！');
            }

        });
    }


});

$(document).on("click", ".itemuse", function () {
    var hash = $(this).attr('hash');
    if (confirm("确认吗？")) {
        var post = {};
        post["hash"] = hash;
        $.post('/Interesting/U', post, function (data) {
            if (data == "Error")
                alert('操作失败！');
            else if (data == "Cant")
                alert('你不能使用它');
            else {
                $('#showbackpack').click();
                alert('操作成功！');
            }
        });

    }


});


$(document).on("click", ".viewstatus", function () {
    $('.statuses').show();

});

$(document).on('click', '.skillenable', function () {

    var hash = $(this).attr('itemid');
    if (confirm("确认吗？")) {
        var post = {};
        post["hash"] = hash;
        $.post('/Interesting/E', post, function (data) {
            if (data == "Error")
                alert('操作失败！');
            else if (data == "Cant")
                alert('你不能禁用它');
            else {
                $('#showskill').click();
                alert('操作成功！');
            }
        });

    }

});